<?php
/**
 * Created by PhpStorm.
 * User: fanfzj
 * Date: 2015/3/29
 * Time: 18:05
 * Name：博客
 */
//if (!defined('BASEPATH')) exit('No direct script access allowed');

class Blog extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
    }

    //首页
    function index()
    {
        //缓存60分钟更新一次
        $this->output->cache(60);
        //记录访客记录
        $this->load->model('Visitinfo_model', 'visit_info', TRUE);
        $tf = $this->visit_info->set_visit_info();

        //模型操作，图片轮播图片列表
        $this->load->model('Backgroudurl_model', 'image', TRUE);
        $data['image_list'] = $this->image->show_image_list();

        //模型操作,关于我
        $this->load->model('Aboutme_model', 'about_me', TRUE);
        $data['about_me'] = $this->about_me->show_me_info();

        //模型操作,标签云
        $this->load->model('Label_model', 'label', TRUE);
        $data['label_list'] = $this->label->show_label_list();

        //模型操作,最近文章
        $this->load->model('Word_model', 'word', TRUE);
        $data['word_list'] = $this->word->show_word_list(0, 3);

        //模型操作,友情链接
        $this->load->model('Friendhref_model', 'friend_href', TRUE);
        $data['friend_list'] = $this->friend_href->show_friend_href_list();
        //显示日历
        $data['calendar'] = $this->show_calendar();

        //页面加载
        $this->load->view('header', $data);
        $this->load->view('index_header');
        $this->load->view('index');
        $this->load->view('index_aside');
        $this->load->view('footer');
    }

//日历
    function  show_calendar()
    {
        $prefs['template'] = '

           {table_open}<table class="table"  border="0" cellpadding="0" cellspacing="0" >{/table_open}

           {heading_row_start}<tr>{/heading_row_start}

           {heading_previous_cell}<th><a href="{previous_url}">&lt;&lt;</a></th>{/heading_previous_cell}
           {heading_title_cell}<th class="text-center" colspan="{colspan}">{heading}</th>{/heading_title_cell}
           {heading_next_cell}<th><a href="{next_url}">&gt;&gt;</a></th>{/heading_next_cell}

           {heading_row_end}</tr>{/heading_row_end}

           {week_row_start}<tr>{/week_row_start}
           {week_day_cell}<td>{week_day}</td>{/week_day_cell}
           {week_row_end}</tr>{/week_row_end}

           {cal_row_start}<tr>{/cal_row_start}
           {cal_cell_start}<td>{/cal_cell_start}

           {cal_cell_content}<a href="{content}">{day}</a>{/cal_cell_content}
           {cal_cell_content_today}<div class="highlight"><a href="{content}">{day}</a></div>{/cal_cell_content_today}

           {cal_cell_no_content}{day}{/cal_cell_no_content}
           {cal_cell_no_content_today}<div class="highlight">{day}</div>{/cal_cell_no_content_today}

           {cal_cell_blank}&nbsp;{/cal_cell_blank}

           {cal_cell_end}</td>{/cal_cell_end}
           {cal_row_end}</tr>{/cal_row_end}

           {table_close}</table>{/table_close}
        ';


        $this->load->library('calendar', $prefs);

        return $this->calendar->generate();
    }

    function page()
    {
        $page = $this->input->post('page');
        $limit = $this->input->post('limit');
        $this->load->model('Word_model', 'word', TRUE);
        $word = $this->word->show_word_list($page, $limit);
        echo json_encode($word);
    }

    function test()
    {
        $this->load->model('Systemblog_model', 'test', TRUE);
        $word = $this->test->show_blog(date('Y-m-d'), date('Y-m-d', strtotime("1 days ago")));
        var_dump($word);
    }

    //音乐
    function get_music()
    {
        $music_num = $this->input->post("music_num");
        $style = $this->input->post("style");
        $this->load->model('Music_model', 'music', TRUE);
        $music = $this->music->play_music($music_num, $style);
        echo json_encode($music);
    }
}